require 'platform'
require 'globals'

class Resource < ActiveRecord::Base
  file_column :file, :root_path => $RESOURCE_ROOT_PATH, :after_upload => [:set_file_fields]
  validates_presence_of :file, :title
  
  def set_file_fields
    self.ext = File.extname(self.file)
    self.thumbnail = $THUMBNAILS[self.ext] unless self.thumbnail.length > 0
    self.file_size = File.size(self.file)
    save!
  end
  
  def filename
    title + ext
  end
end
